package qualification_round;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;


public class TidyNumbers {

	public static int CHAR_ZERO = 48; 
	
	public static void main(String[] args) {
		Scanner sc = null;
        try {
        	sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
            int tests = sc.nextInt();
            
            for (int t = 1; t <= tests; t++) {
                char[] numChars = sc.next().toCharArray();       
                
                int[] digits = new int[numChars.length];
                for (int i = 0; i < digits.length; i++) 
                	digits[i] = numChars[i] - CHAR_ZERO;                	
                
                boolean finished = false;
                while (!finished)
                {
	                for (int i = 0; i < digits.length - 1; i++)	                
	                	if (digits[i] > digits[i+1])
	                	{
	                		int borrow = 1;
	                		for (int j = i; j >= 0; j--)
	                		{
	                			if (digits[j] < borrow)
	                			{
	                				digits[j] = 9;
	                				borrow = 1;
	                			}
	                			else
	                			{
	                				digits[j] -= borrow;
	                				borrow = 0;
	                				break;
	                			}
	                		}
	                		for (int j = i+1; j < digits.length; j++)
	                			digits[j] = 9;
	                		break;
	                	}                	                
	                
	                finished = true;
	                for (int i = 0; i < digits.length - 1; i++)	                	                
	                	if (digits[i] > digits[i+1])
	                		finished = false;	                
                }
                
                System.out.printf("Case #%d: ", t);
                boolean firstZero = true;
                for (int i = 0; i < digits.length; i++)
                	if (!firstZero || digits[i] > 0)
                	{
                		firstZero = false;
                		System.out.print(digits[i]);
                	}
                System.out.printf("");
            }
        }
        catch (Exception e)
        {
        	System.out.printf(e.getMessage());
        	if (sc != null)	
        		sc.close();
        }        
    }
}
